home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-02 / swindows.zip / WINDOWS.DOC < prev   
Text File  |  1990-04-10  |  8KB  |  142 lines

  1.                                 Simple Windows
  2.                          SWINDOWS.TPU and HWINDOWS.TPU
  3.                      Screen Windows Units for Turbo Pascal
  4.                              by David C. Swaim II
  5.  
  6.  
  7.           The   SWINDOWS.TPU   and   HWINDOWS.TPU  files  are  Turbo Pascal
  8.     (version 5.5) Units used for creating  screen  windows  in  application
  9.     programs.   The two units differ in the way the screens are stored when
  10.     a window is opened.  When a window is open the  original  screen  under
  11.     the  window  must be saved so the screen can be returned to normal when
  12.     the window is closed.  The  routines  on  these  units  will  save  and
  13.     restore  the  screen  automatically when the OpenWindow and CloseWindow
  14.     procedures are called.
  15.  
  16.           SWINDOWS.TPU stores the screen data in the data segment (or stack
  17.     if  you  define  your WindowStorage variable inside a procedure).  This
  18.     has the disadvantage of reducing the amount of  storage  left  for  the
  19.     rest  of your application program.  The advantage in storing the screen
  20.     data this way is that you can zero the stack allocation so you can  use
  21.     the EXEC procedure to execute a child process (another program).  I use
  22.     this unit in several menu shell programs I have written.
  23.  
  24.           There are only two procedures to learn for the SWINDOWS.TPU.  The
  25.     first  of  these  opens a window on the screen and is called OpenWindow
  26.     (what else?).  The procedure is declared by:
  27.  
  28.     procedure OpenWindow(X1,Y1,X2,Y2,TxtColor,BgColor: byte;
  29.                          Frame: boolean;
  30.                          Title: WindowTitle;
  31.                          var Stuff: WindowStorage);
  32.  
  33.     Where X1 and Y1 are the x,y (column,row) coordinates of the upper  left
  34.     corner  of  the  window  and X2 and Y2 are the coordinates of the lower
  35.     right corner.  TxtColor is the color of the frame if one  is  requested
  36.     and  BgColor is the background color of the window.  If Frame is true a
  37.     double line box frame is drawn around the window.  Title is  the  title
  38.     of  the window and is a string which will appear in the top left of the
  39.     window  frame.   Stuff  is a variable where the original screen data is
  40.     stored.  You must declare a variable of type WindowStorage to  pass  to
  41.     the OpenWindow routine for it to store screen data into.  Once a window
  42.     is open you can write to it using the Write or Writeln procedures.  Any
  43.     GotoXY  procedure  is  relative  to the current window.  The OpenWindow
  44.     procedure calls the Turbo Pascal Window procedure using X1, Y1, X2  and
  45.     Y2.
  46.  
  47.           The second procedure is called CloseWindow and it  will  close  a
  48.     window that you have previously opened.  The procedure is declared by:
  49.  
  50.     procedure CloseWindow(X1,Y1,X2,Y2: byte;
  51.                           Stuff: WindowStorage);
  52.  
  53.     Where X1, Y1, X2 and Y2 are as defined in OpenWindow and Stuff is where
  54.     the screen data for this window was stored  when  you  opened  it  with
  55.     OpenWindow.
  56.  
  57.           There  are  a  few  simple rules you must follow when using these
  58.     window routines.  As long as you open only one window  at  a  time  you
  59.     will  need only one WindowStorage variable which you can reuse for each
  60.     window.  If you want to overlay windows (one window opens and a  second
  61.     window  is  open  over it) you can do that by calling OpenWindow again.
  62.     You must have a second variable of type WindowStorage to put the second
  63.     window data into.  When you go to close the windows they must be closed
  64.     in reverse order from the order in which  they  were  opened  (last-in,
  65.     first-out).   If you close the second window and want to make the first
  66.     window active again you must be sure that you execute the Turbo  Pascal
  67.     Window  procedure  with  the  x,y  coordinate  information of the first
  68.     window.  This is because the CloseWindow procedure executes  the  Turbo
  69.     Pascal  Window  procedure with the call: Window(1,1,80,25).  This makes
  70.     all GotoXY calls relative to the entire screen instead of  relative  to
  71.     the previous window.  Example:
  72.  
  73.           {  Open First Window  }
  74.           OpenWindow(X1f,Y1f,X2f,Y2f,TxtColorf,BgColorf,
  75.                      True,"First Window",Stuff1);
  76.  
  77.           {  Open Second Window  }
  78.           OpenWindow(X1s,Y1s,X2s,Y2s,TxtColors,BgColors,
  79.                      True,"Second Window",Stuff2);
  80.  
  81.           {  Now close second window and make first window current  }
  82.           CloseWindow(X1s,Y1s,X2s,Y2s,Stuff2);
  83.           Window(X1f,Y1f,X2f,Y2f);
  84.  
  85.           {  Now close first window  }
  86.           CloseWindow(X1f,Y1f,X2f,Y2f,Stuff1);
  87.  
  88.     X1f, Y1f, X2f and Y2f are the  coordinates  of  the  first  window  and
  89.     TxtColorf  and  BgColorf  are the color attributes of the first window.
  90.     Stuff1 is the WindowStorage  variable  where  the  original  screen  is
  91.     stored.  X1s, Y1s, X2s and Y2s are the coordinates of the second window
  92.     and  TxtColors  and  BgColors  are  the  color attributes of the second
  93.     window.   Stuff2  is  the  WindowStorage  variable  where  the   screen
  94.     containing the first window is stored.
  95.  
  96.           HWINDOWS.TPU  (HeapWindows)  contains  four procedures.  The same
  97.     open and close window procedures are there along with save and  restore
  98.     screen  procedures.  Some programs give you the option of restoring the
  99.     original DOS screen on termination.  This can be done in your  programs
  100.     by  calling  SaveScreen  at  the  start of the program and then calling
  101.     RestoreScreen at the end.  Be sure you save the cursor location at  the
  102.     beginning of your program so you can place the cursor back where it was
  103.     at the end of your program.  The two procedures are declared:
  104.  
  105.     Procedure SaveScreen(var StashPtr: Pointer);
  106.  
  107.     Procedure RestoreScreen(StashPtr: Pointer);
  108.  
  109.     Where  StashPtr  is the pointer to the location of the screen data that
  110.     is stored in the heap.
  111.  
  112.           The open and close window procedures  look  just  like  the  ones
  113.     described  above  for  SWINDOWS.TPU  except  for  one  difference.  The
  114.     variable Stuff is now just a pointer to the location of the screen data
  115.     in the heap.  So the declarations look like this:
  116.  
  117.     procedure OpenWindow(X1,Y1,X2,Y2,TxtColor,BgColor: byte;
  118.                          Frame: boolean;
  119.                          Title: WindowTitle;
  120.                          var Stuff: Pointer);
  121.  
  122.  
  123.     procedure CloseWindow(X1,Y1,X2,Y2: Byte;
  124.                           Stuff: Pointer);
  125.  
  126.     All other parameters passed to these procedures are the same as in  the
  127.     SWINDOWS.TPU.
  128.  
  129.           Because  the  SWINDOWS.TPU  saves screens in the data segment and
  130.     because it saves only the  screen  data  under  the  opened  window  it
  131.     operates  slightly faster than the HWINDOWS.TPU.  This speed difference
  132.     is only noticable on the slower XT type computers and then only when it
  133.     has the old CGA color graphics.  This is because the windows procedures
  134.     access the screen memory only when the raster scan  is  turned  off  to
  135.     avoid  the  "snow" that you get when accessing screen RAM when scanning
  136.     is taking place.  The  HWINDOWS.TPU  procedures  are  a  little  slower
  137.     because  they save the entire screen instead of just the part under the
  138.     window.  Both units initialize themselves by checking to see  what type
  139.     of video adapter is installed on the computer.  They do "snow checking"
  140.     only on CGA adapters.
  141.  
  142.